package com.jhd.fuzhou.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

public class DateTime {
    public static String getYear(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy");
        Date date = new Date();
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        return format.format(now.getTime());
    }

    public static String getTodayDate(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        return format.format(now.getTime());
    }
    public static String getTodayStart(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar now = Calendar.getInstance();
        return format.format(now.getTime())+" 00:00:00";
    }
    public static String getTodayEnd(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar now = Calendar.getInstance();
        return format.format(now.getTime())+" 23:59:59";
    }
    public static List<String> getToday(){
        List<String> dateList=new ArrayList<>();
        dateList.clear();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        dateList.add(format.format(now.getTime())+" 00:00:00");
//        now.add(Calendar.DAY_OF_MONTH, +1);
        dateList.add(format.format(now.getTime())+" 23:59:59");
        return dateList;
    }
    public static List<String> getYesterday(){
        List<String> dateList=new ArrayList<>();
        dateList.clear();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar now = Calendar.getInstance();
        now.setTime(date);
        now.add(Calendar.DAY_OF_MONTH, -1);
        dateList.add(format.format(now.getTime())+" 00:00:00");
        dateList.add(format.format(now.getTime())+" 23:59:59");
        return dateList;
    }

    public static List<String> getWeek(){
        List<String> dateList=new ArrayList<>();
        dateList.clear();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        Calendar now = Calendar.getInstance();
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();
        start.setTime(date);end.setTime(date);
        int curDay = now.get(Calendar.DAY_OF_WEEK);
        now.setTime(date);
        if(curDay==1){
            dateList.add(format.format(start.getTime())+" 00:00");
            end.add(Calendar.DAY_OF_MONTH,+7);
            dateList.add(format.format(end.getTime())+" 00:00");
        }else{
            start.add(Calendar.DAY_OF_MONTH,1-curDay);
            dateList.add(format.format(start.getTime())+" 00:00:00");
            end.add(Calendar.DAY_OF_MONTH,7-curDay);
            dateList.add(format.format(end.getTime())+" 23:59:59");
        }
        return dateList;
    }
    public static List<String> getMoon(Date date){
        List<String> dateList=new ArrayList<>();
        dateList.clear();
        dateList.add(getSupportBeginDayofMonth(date));
        dateList.add(getSupportEndDayofMonth(date));
        return dateList;
    }
    /**
     * 根据提供的年月日获取该月份的第一天
     * @Description: (这里用一句话描述这个方法的作用)
     * @Author: gyz
     * @Since: 2017-1-9下午2:26:57
     * @param date
     *
     * @return
     */
    public static String getSupportBeginDayofMonth(Date date) {
        date.getTime();
        Calendar startDate = Calendar.getInstance();
        startDate.setTime(date);
        startDate.set(Calendar.DAY_OF_MONTH, 1);
        startDate.set(Calendar.HOUR_OF_DAY, 0);
        startDate.set(Calendar.MINUTE, 0);
        startDate.set(Calendar.SECOND, 0);
        startDate.set(Calendar.MILLISECOND, 0);
        Date firstDate = startDate.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(firstDate);

    }

    /**
     * 根据提供的年月获取该月份的最后一天
     * @Description: (这里用一句话描述这个方法的作用)
     * @Author: gyz
     * @Since: 2017-1-9下午2:29:38
     * @param date
     * @return
     */
    public static String getSupportEndDayofMonth(Date date) {
        Calendar startDate = Calendar.getInstance();
        startDate.setTime(date);
        startDate.set(Calendar.DAY_OF_MONTH, startDate.getActualMaximum(Calendar.DAY_OF_MONTH));
        startDate.set(Calendar.HOUR_OF_DAY, 23);
        startDate.set(Calendar.MINUTE, 59);
        startDate.set(Calendar.SECOND, 59);
        startDate.set(Calendar.MILLISECOND, 999);
        Date firstDate = startDate.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(firstDate);
    }

    public static String setTime(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(date);
    }
    public static String getPhotoNum(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        return format.format(date);
    }
    /*将yyyy:MM:dd HH:mm:ss转yyyy-MM-dd HH:mm:ss*/
    public static String changeStyle(String date){
        String first=date.substring(0,11);
        String second=date.substring(11);
        return first.replace(":","-")+second;
    }
    public static Date setDate(String date){
        DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1 = null;
        try {
           date1 =fmt.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date1;
    }

}
